/*
 * Copyright Hundsun Technologies Inc. All Rights Reserved.
 */

package common

import (
	"context"

	uberatomic "go.uber.org/atomic"
	"hundsun.com/hsl/hschain/common/log/logging"
	"hundsun.com/hsl/hschain/consensus/common"
	"hundsun.com/hsl/hschain/module"
)

// miner模块可以集群部署，此文件中存放多个miner之间需要共享的内容

const minerIndexNotFound = -1

var log logging.Log
var initialized *uberatomic.Bool

// Initialize 初始化（只能被成功调用一次）
func Initialize(ctx context.Context, minerLog logging.Log, client *common.BaseClient) error {
	log = logging.NewLog(minerLog.GetLevel(), logging.LogFieldModule, module.ConsensusModuleName)
	initialized = uberatomic.NewBool(false)

	err := initRoundCommon(ctx, client)
	if err != nil {
		return err
	}
	err = initBlockCommon(client)
	if err != nil {
		return err
	}
	initialized.Store(true)
	log.Info("miner-shared members initialized")
	return nil
}
